# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def sortList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head:
            return None
        a = []
        l = ListNode(0)
        l.next = head
        while head:
            a.append(head.val)
            head = head.next

        a = sorted(a)
        f = l
        for i in a:
            s = ListNode(i)
            l.next = s
            l = l.next
        return f.next
